import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete
} from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { ApiBearerAuth } from '@nestjs/swagger';
import { RoleService } from './role.service';
import {
  CreateRoleDto,
  UpdateRoleDto
} from '../../../../libs/db/src/schemas/role.schemas';
import { QueryRoleDto } from './dto/queryRoleDto';
import { roleNormalize as norm } from '../../normalize';

@Controller(norm.path)
@ApiTags(norm.tag)
@ApiBearerAuth()
export class RoleController {
  constructor(private readonly roleService: RoleService) {}

  @Post(norm.create.path)
  @ApiOperation({ summary: norm.create.tag })
  create(@Body() createRoleDto: CreateRoleDto) {
    return this.roleService.create(createRoleDto);
  }

  @Post(norm.page.path)
  @ApiOperation({ summary: norm.page.tag })
  pageQuery(@Body() dto: QueryRoleDto) {
    return this.roleService.pageQuery(dto);
  }

  @Get(norm.list.path)
  @ApiOperation({ summary: norm.list.tag })
  findAll() {
    return this.roleService.findAll();
  }

  @Get(norm.detail.path)
  @ApiOperation({ summary: norm.detail.tag })
  findOne(@Param(norm.detail.arg) id: string) {
    return this.roleService.findOne(id);
  }

  @Patch(norm.update.path)
  @ApiOperation({ summary: norm.update.tag })
  update(
    @Param(norm.update.arg) id: string,
    @Body() updateRoleDto: UpdateRoleDto
  ) {
    return this.roleService.update(id, updateRoleDto);
  }

  @Delete(norm.delete.path)
  @ApiOperation({ summary: norm.delete.tag })
  remove(@Param(norm.delete.arg) id: string) {
    return this.roleService.remove(id);
  }
}
